package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.base.AjaxResult;
import com.whnk.common.utils.ExcelUtil;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.EmpInfo;
import com.whnk.pm.service.IEmpInfoService;

/**
 * 报表  信息操作处理
 * 
 * @author whwhnk
 * @date 2019-06-17
 */
@Controller
@RequestMapping("/pm/empInfo")
public class EmpInfoController extends BaseController
{
    private String prefix = "pm/empInfo";
	
	@Autowired
	private IEmpInfoService empInfoService;
	
	@RequiresPermissions("pm:empInfo:view")
	@GetMapping()
	public String empInfo()
	{
	    return prefix + "/empInfo";
	}
	
	/**
	 * 查询人员基本列表
	 */
	@RequiresPermissions("pm:empInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo empList(EmpInfo empInfo)
	{
		startPage();
		String name = empInfo.getEmpNm();
		if (StringUtils.isNotBlank(name)) {
			empInfo.setEmpNames(name.split(";"));
		}
        List<EmpInfo> list = empInfoService.selectEmpInfoList(empInfo);
		return getDataTable(list);
	}
	
	/**
	 * 导出维护人员基本信息表
	 * 
	 * @param empInfo
	 * @return
	 */
    @RequiresPermissions("pm:empInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EmpInfo empInfo)
    {
		String name = empInfo.getEmpNm();
		if (StringUtils.isNotBlank(name)) {
			empInfo.setEmpNames(name.split(";"));
		}
		List<EmpInfo> list = empInfoService.selectEmpInfoList(empInfo);
        ExcelUtil<EmpInfo> util = new ExcelUtil<EmpInfo>(EmpInfo.class);
        return util.exportExcel(list, "empInfo");
    }

    @PostMapping(value = "/refresh")
	@ResponseBody
    public AjaxResult refresh() {
		empInfoService.statisticsInfo();
    	return success();
	}
}
